package com.efrei.schoolmanager.model.hibernate.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import com.efrei.schoolmanager.model.dao.HibernateDAO;
import com.efrei.schoolmanager.model.obj.Eleve;

/**
 * DAO pour les eleves avec hibernate
 */
public class EleveDAO extends HibernateDAO<Eleve> {

	public EleveDAO(Session session) {
		super(session, Eleve.class);
	}

	public List<Eleve> getEleves() throws HibernateException {
		return content("FROM Eleve ORDER BY matricule, nom, prenom");
	}

	/**
	 * retourne l'eleve en base selon le matricule donné
	 * 
	 * @param matricule
	 * @return
	 * @throws HibernateException
	 */
	@SuppressWarnings("unchecked")
	public List<Eleve> getEleveByMatricule(String matricule)
			throws HibernateException {
		String hql = "from Eleve e WHERE e.matricule = :matricule";
		Query request = getSession().createQuery(hql).setString("matricule",
				matricule);
		return request.list();
	}
}
